<template>
    <div class="shopcar-cotainer">   
        <!-- 商品列表选项区域 -->
        <div class="mui-card" v-for="(item,i) in goodsList" :key="item.id">
            <div class="mui-card-content">
                <div class="mui-card-content-inner">
                    <mt-switch v-model="$store.getters.getSelected[item.id]" @change="selectedChange(item.id,$store.getters.getSelected[item.id])"></mt-switch>
                    <img :src="item.thumb_path">
                    <div class="info">
                        <h1>{{item.title}}</h1>
                        <p>
                            <span class="price">￥{{item.sell_price}}</span>
                            <shopcar :initCount="$store.getters.getGoodsCount[item.id]" :goodsId="item.id"></shopcar>
                            <a href="#" @click.prevent="remove(item.id,i)">删除</a>
                        </p>
                    </div>
                </div>
            </div>
        </div> 

        <!-- 结算区域 -->
        <div class="mui-card">
            <div class="mui-card-content">
                <div class="mui-card-content-inner"> 
                    <div>
                        <p>总计(不包含运费)</p>
                        <p>已勾选商品<span class="red">{{$store.getters.getCountAndAmount.count}}</span>件，总价<span class="red">￥{{$store.getters.getCountAndAmount.amount}}</span></p>
                    </div>
                    <mt-button type="danger">去结算</mt-button>
                </div> 
            </div>
        </div>
    </div>
</template>
<script>
import shopcar from '../subcomponents/shopcar-numberbox.vue';
export default{
    data(){
        return {
            goodsList:[]
        }
    },
    created(){
        this.addGoods();
    },
    methods:{
        addGoods(){
            var idArr = [];
            this.$store.state.car.forEach(item=>idArr.push(item.id));
            if(idArr.length<=0){
                return;
            }
            this.$http.get("../mydata/goodsCar/1.json").then(result=>{
                console.log("dd");
                if(result.body.status===0){
                    console.log(result);
                    this.goodsList = result.body.message;
                }
            });
        },
        remove(id,i){ 
            console.log("dd");
            console.log(this.goodsList);
            this.goodsList.splice(i,1); 
            this.$store.commit("remove",id);
        },
        selectedChange(id,val){
            this.$store.commit("updateSelected",{id,selected:val})
        }
    },
    components:{
        shopcar
    }
}
</script>

<style  scoped>
    .shopcar-cotainer{
        background-color: #eee;
        overflow: hidden;
    }
    
    .shopcar-cotainer .mui-card-content-inner{
        display: flex;
        align-items: center;
        justify-content:space-between;
    }
    .shopcar-cotainer .mui-card-content-inner img{
        width: 60px;
        height: 60px;
        margin: 0 5px;
    }
     .shopcar-cotainer h1{
         font-size: 13px;
     }
     .info{
         display: flex;
         flex-direction: column;
         justify-content: space-between;
     }
     .info .price{
         color: red;
         font-weight: bold;
     }
     .mui-card-content-inner .left{
         display: flex;
         align-items: center;
         justify-content:space-between;
     }
     .mui-card-content-inner .red{
         font-size: 16px;
         color: red;
         font-weight: bold;
     } 
</style>
